﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GalaSoft.MvvmLight.Messaging;

namespace GiveAQuiz.QuizManager
{
  /// <summary>
  /// Class to support app-wide messaging while being loosely coupled.
  /// </summary>
  public static class AppMessages
  {
    enum MessageTypes
    {
      IsBusyMsg,
      EditDetails,
      ShowMessage,
      ShowDialog,
      ShowMessageAndRedirect    
    }

    public static class IsBusyMessage
    {
      public static void Send(bool isBusy)
      {
        Messenger.Default.Send<bool>(isBusy, MessageTypes.IsBusyMsg);
      }

      public static void Register(object recipient, Action<bool> action)
      {
        Messenger.Default.Register<bool>(recipient, MessageTypes.IsBusyMsg, action);
      }
    }

    public static class EditDetailsMessage
    {
      public static void Send()
      {
        // Must use a parameterized send/recieve 
        // since the Messenger doesn't support 
        // simple messages
        Messenger.Default.Send<bool>(true, MessageTypes.EditDetails);
      }

      public static void Register(object recipient, Action<bool> action)
      {
        Messenger.Default.Register<bool>(recipient, MessageTypes.EditDetails, action);
      }
    }

    public static class ShowMessage
    {
      public static void Send(string msg)
      {
        Messenger.Default.Send<string>(msg, MessageTypes.ShowMessage);
      }

      public static void Register(object recipient, Action<string> action)
      {
        Messenger.Default.Register<string>(recipient, MessageTypes.ShowMessage, action);
      }
    }

    public static class ShowMessageAndRedirect
    {
      public static void Send(string msg, Uri redirect)
      {
        Messenger.Default.Send<Tuple<string, Uri>>(new Tuple<string, Uri>(msg, redirect), MessageTypes.ShowMessageAndRedirect);
      }

      public static void Register(object recipient, Action<Tuple<string, Uri>> action)
      {
        Messenger.Default.Register<Tuple<string, Uri>>(recipient, MessageTypes.ShowMessageAndRedirect, action);
      }
    }

    public static class ShowDialog
    {
      public static void Send(ChildWindow dialogToShow, Action callback)
      {
        Messenger.Default.Send<Tuple<ChildWindow, Action>>(new Tuple<ChildWindow, Action>(dialogToShow, callback), MessageTypes.ShowDialog);
      }

      public static void Register(object recipient, Action<Tuple<ChildWindow, Action>> action)
      {
        Messenger.Default.Register<Tuple<ChildWindow, Action>>(recipient, MessageTypes.ShowDialog, action);
      }
    }

  }
}
